<!--设备选择器 可以根据变电站选择保护设备（故障档案填写专用） -->
<!DOCTYPE html	PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:s="http://sduept.security.el/func"
	template="/template/template_dialog.xhtml">
	
	<ui:define name="head">
		<title>设备选择器</title>
		<style type="text/css">
			.value {
				font-weight: bold;
			}
			
			.ui-tree {
				width: 400px;
				position: relative;
				height: 300px;
				overflow-y: scroll;
			}
			
			input[type="text"] {
				height: 21px;
			}
		</style>
	</ui:define>
	<!-- 
	layer.js打开的窗口中用到设备选择器时，选择本页面。
	需要在父xhtml中添加primeface代码：
	<p:commandButton value="添加主保护" onclick="openNeedDeviceDialog('zbhdz','#{acLineFaultReportController.faultReportMain.faultRecord.equipment_id}','#{acLineFaultReportController.secondStationDetail.stationId}');" icon="ui-icon-document"/>
	<p:remoteCommand name="onDeviceDialogReturn" actionListener="#{acLineFaultReportController.onDeviceDialogReturn}"/>
	需要在父xhtml中添加script代码：
	var needDeviceDialogIndex;
	//此方法与上面添加主保护时的方法名和参数一致即可
	//打开设备选择器页面
	function openNeedDeviceDialog(type,deviceId,stationId){
		var params = "stationId="+ stationId+"&amp;protectionType="+type+"&amp;deviceId="+deviceId;
		var src = '/ui/common/equipment_selector_faultReport_protectiont_layer.xhtml?'+params;
		
		needDeviceDialogIndex = layer.open({
			  type: 2,
			  maxmin :false,
			  area: ['610px', '462px'],
			  fixed: false, //不固定
			  title:'设备选择器',
			  maxmin: true,
			  content: src
			});
	}
	//此方法名不可更改
	function dialogReturn(index,data){
		var params = [];
		data = eval("("+data+")");
		if(index == needDeviceDialogIndex){
			params.push({name:'className',value:data.className},{name:'data',value:data.data},{name:'type',value:data.type});
			onDeviceDialogReturn(params);
		}
	}
	需要在打开此选择器的页面的controller中添加如下方法：
	//此方法与primeface中调用的方法名一致即可
	public void onDeviceDialogReturn() {
		String data = getParameter("data");
		String className = getParameter("className");
	//	type为打开页面时传递的type，不同type对应不同的类型的data数据
		String type = getParameter("type");
		if("zbhdz".equals(type) && ProtectionEquipment.class.getSimpleName().equals(className)){
			ProtectionEquipment pe = JSONObject.parseObject(data, ProtectionEquipment.class);
			//业务逻辑
		}else if("dlqbhdzxx".equals(type) && ProtectionEquipment.class.getSimpleName().equals(className)){
			ProtectionEquipment pe = JSONObject.parseObject(data, ProtectionEquipment.class);
			//业务逻辑
		}else if("dlqdzxx".equals(type) && Breaker.class.getSimpleName().equals(className)){
			Breaker b = JSONObject.parseObject(data, Breaker.class);
			//业务逻辑
		}else{
			return;
		}
		//更新前台表格，不知为何这里从前台无法直接更新表格
		RequestContext.getCurrentInstance().update(Arrays.asList("form1:stations:fdt","form1:stations:fbdt","form1:stations:sdt","form1:stations:sbdt"));
	}
	} -->
	<ui:define name="content">
		<h:form id="toolbarForm">
			<p:toolbar id="toolbar">
				<f:facet name="left">
					<p:commandButton value="确定" icon="ui-icon-disk" update="selectedEquipmentJson" oncomplete="closeAndSave();"
						 actionListener="#{equipmentSingleSelectorFaultReportLayerController.selectEquipment}" />
					<p:commandButton value="设备维护" oncomplete="openProtectAccountDialog();"/>
					<h:inputHidden id="selectedEquipmentJson" value="#{equipmentSingleSelectorFaultReportLayerController.selectedEquipmentJson}" />
				</f:facet>
			</p:toolbar>
		</h:form>
		<h:form id="deviceForm">
			<p:tree value="#{equipmentSingleSelectorFaultReportLayerController.root}" var="node"
				style="width:600px;border:none" dynamic="true" id="tree" widgetVar="tree" animate="true"
				selectionMode="single" selection="#{equipmentSingleSelectorFaultReportLayerController.selectedNode}">
				<p:ajax event="expand" update="deviceForm:tree"
					listener="#{equipmentSingleSelectorFaultReportLayerController.onNodeExpand}" />
				<p:ajax event="select" 
					listener="#{equipmentSingleSelectorFaultReportLayerController.onNodeSelect}" />
				<p:treeNode type="1" icon="fa fa-folder-open-o">
					<h:outputText value="#{node}" />
				</p:treeNode>
				<p:treeNode type="ProtectionEquipment" icon="fa fa-home ">
					<h:outputText value="#{node}" />
				</p:treeNode>
				<p:treeNode type="Breaker" icon="fa fa-home ">
					<h:outputText value="#{node}" />
				</p:treeNode>
				<p:treeNode type="All" icon="fa fa-folder-open-o">
					<h:outputText value="#{node}" />
				</p:treeNode>
			</p:tree>
		</h:form>
		<script>
			var protectAccountDialogIndex;
			function closeAndSave(){
				var index = parent.layer.getFrameIndex(window.name);
				var jsonData = document.getElementById("toolbarForm:selectedEquipmentJson").value;
				if(parent.dialogReturn){
					parent.dialogReturn(index,jsonData);
				}
				parent.layer.close(index);
			}
			function openProtectAccountDialog(){
				if(parent.openProtectAccountDialog){
					parent.openProtectAccountDialog();
				}else{
					protectAccountDialogIndex = layer.open({
						  type: 2,
						  maxmin :false,
						  area: ['1250px', '750px'],
						  fixed: false, //不固定
						  title:'人员选择器',
						  maxmin: true,
						  content: '/ui/dataview/devicefault/protectAccountDialog.xhtml',
						});
				}
			}
	
		</script>
	</ui:define>
</ui:composition>
